package sng.modules.view.components
{
	
	import flash.display.Loader;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.net.URLRequest;
	
	import mx.containers.Canvas;
	import mx.core.UIComponent;
	import mx.events.FlexEvent;
	import mx.states.AddChild;
	
	public class MapBG extends Sprite
	{
		public function MapBG()
		{
			super();
			
			var loader:Loader = new Loader();
			loader.load(new URLRequest("assets/bg.png"));//../../assets/bg.png
			this.addChild(loader);
			
			
			addEventListener(MouseEvent.MOUSE_DOWN,mousedown);
			addEventListener(MouseEvent.MOUSE_UP,mouseup);
			addEventListener(MouseEvent.MOUSE_MOVE,mousemove);
			
			this.addEventListener(Event.ENTER_FRAME,BG_control);
			
		}		
		private var _blDown:Boolean=false;
		private var blbgDrag:Boolean=false;
		
		
		private function mousedown(evt:MouseEvent):void
		{
			this.startDrag();
			_blDown = true;
		}
		
		//地图拖动
		protected function mousemove(evt:MouseEvent):void
		{
			if (_blDown)
			{
				blbgDrag = true;
			}
		}
		
		//地图停止拖动
		protected function mouseup(evt:MouseEvent):void
		{
			this.stopDrag();
			blbgDrag = false;
			_blDown = false;
		}
		
		//地图坐标调整
		protected function BG_control(evt:Event):void
		{
			if (stage!=null)
			{
				if (x < stage.stageWidth - width)
				{
					x = stage.stageWidth - width;
				}
				if (x > 0)
				{
					x = 0;
				}
				
				if (y < stage.stageHeight- height)
				{
					y = stage.stageHeight - height;
				}
				if (y > 0)
				{
					y = 0;
				}
			}
		}
		
		
	}
}